package com.zr.lads.action;

import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.lads.service.OrderService;
import com.zr.lads.util.PrintWriterUtil;

import net.sf.json.JSONObject;

/**
 *  查询所有订单
 * @author Windy--Chow
 *
 */
@Controller
@Scope(value="prototype")
public class selectAllOrdersAction extends ActionSupport implements SessionAware,ServletResponseAware{
    /**
     * 
     */
	private static final long serialVersionUID = 1L;
	
	private int page;
	private int rows;
	private String orderReceiverName;
	private String orderProviderName;
	private String orderState;
	private String orderReceiverAddr;
	private String orderProviderAddr;
	private String begintime;
	private String endtime;
	
	 @Resource
	 private OrderService orderService;
	
	
	
	private HttpServletResponse resp;
	private Map<String, Object> session;
	
	
	
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}
    
	public String getOrderReceiverName() {
		return orderReceiverName;
	}

	public void setOrderReceiverName(String orderReceiverName) {
		this.orderReceiverName = orderReceiverName;
	}

	public String getOrderProviderName() {
		return orderProviderName;
	}

	public void setOrderProviderName(String orderProviderName) {
		this.orderProviderName = orderProviderName;
	}

	public String getOrderState() {
		return orderState;
	}

	public void setOrderState(String orderState) {
		this.orderState = orderState;
	}

	public String getOrderReceiverAddr() {
		return orderReceiverAddr;
	}

	public void setOrderReceiverAddr(String orderReceiverAddr) {
		this.orderReceiverAddr = orderReceiverAddr;
	}

	public String getOrderProviderAddr() {
		return orderProviderAddr;
	}

	public void setOrderProviderAddr(String orderProviderAddr) {
		this.orderProviderAddr = orderProviderAddr;
	}

	public String getBegintime() {
		return begintime;
	}

	public void setBegintime(String begintime) {
		this.begintime = begintime;
	}

	public String getEndtime() {
		return endtime;
	}

	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}

	/**
	 * 查询所有订单   +  模糊查询
	 */
	 public void selectAllOrders(){ 
		 String orname = orderReceiverName.replace(" ", "");           //         收件人名去空格
		 String opname = orderProviderName.replace(" ", "");           //         寄件人名去空格
//		 System.out.println(orname.equals(""));
//		 System.out.println(opname.equals(""));
//		 System.out.println(orderState);
		 String oraddr = orderReceiverAddr.replace("null", "");
		 String opaddr = orderProviderAddr.replace("null", "");
		 
		 if(orname!=""||opname!=""||orderState!=null||oraddr!=""||opaddr!=""||begintime!=null||endtime!=null){
			 System.out.println("进来了");
			 System.out.println(oraddr!="");
			 System.out.println(opaddr!="");
			 System.out.println(begintime);
			 System.out.println(endtime);
		 }
		 else{
			 JSONObject order = orderService.selectAllOrders(page, rows);
			 PrintWriter pw = PrintWriterUtil.getPW(resp);
			 pw.write(order.toString());
		 }
			 
	 }
	
	 
	@Override
	public void setServletResponse(HttpServletResponse resp) {
		this.resp = resp;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
}
